package cn.wolfcode.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.wolfcode.business.vo.BusStatementItemVO;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.wolfcode.common.annotation.Log;
import cn.wolfcode.common.core.controller.BaseController;
import cn.wolfcode.common.core.domain.AjaxResult;
import cn.wolfcode.common.enums.BusinessType;
import cn.wolfcode.business.domain.BusStatementItem;
import cn.wolfcode.business.service.IBusStatementItemService;
import cn.wolfcode.common.utils.poi.ExcelUtil;
import cn.wolfcode.common.core.page.TableDataInfo;

/**
 * 结算单明细Controller
 * 
 * @author wolfcode
 * @date 2025-04-07
 */
@RestController
@RequestMapping("/business/item")
public class BusStatementItemController extends BaseController
{
    @Autowired
    private IBusStatementItemService busStatementItemService;

    /**
     * 查询结算单明细列表
     */
    @PreAuthorize("@ss.hasPermi('business:item:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusStatementItem busStatementItem)
    {
        startPage();
        List<BusStatementItem> list = busStatementItemService.selectBusStatementItemList(busStatementItem);
        return getDataTable(list);
    }

    //保存明细项
    @PostMapping
    public AjaxResult itemSave(@RequestBody BusStatementItemVO vo){
        return toAjax(busStatementItemService.itemSave(vo));
    }

    /*根据结算单id查询结算单明细列表*/
    @GetMapping
    public AjaxResult list(Long statementId){
        BusStatementItem busStatementItem = new BusStatementItem();
        //使用statementId查询明细列表
        busStatementItem.setStatementId(statementId);
        return AjaxResult.success(busStatementItemService.selectBusStatementItemList(busStatementItem));
    }

    /*支付功能*/
    @PatchMapping(value = "/{statementId}",headers = "cmd=pay")
    public AjaxResult pay(@PathVariable Long statementId){
        return toAjax(busStatementItemService.pay(statementId));
    }
}
